<?php
require_once 'backend/model/Db.php';
$model = new Db;

function checkCat($uri) {    
    $mod = "home";
    $page_id = "";   
    if (strpos( $uri,'faq')>-1) {        
        $mod = "faq";
    } 
    if (strpos( $uri,'khong-gian-am-thuc')>-1) {        
        $mod = "news";
    }   
    if (strpos( $uri,'chi-tiet')>-1) {        
        $mod = "detail";
    } 
    return array("mod" =>$mod,'page_id' => $page_id);
}

$uri = str_replace("/box", "", $_SERVER['REQUEST_URI']);
$tmpURI = explode("/",$uri);

$arrRS = checkCat($tmpURI[1]);        

$mod = $arrRS['mod']==null ? "home" : $arrRS['mod']; 

$page_id = $arrRS['page_id'];
$uri = str_replace(".html", "", $uri);
$tmp_uri = explode("/", $uri);
switch ($mod) {    
    
    case "news" :          
        $tieude_id = $tmp_uri[2];        
        $arr = explode("-", $tieude_id);   
        $page = (int) end($arr);
        $page = ($page > 0 ) ? $page : 1;
        $limit = 10;
        $offset = ($page - 1)* $limit;
    case "details":  
		$tieude_id = $tmp_uri[3];
        
        $arr = explode("-", $tieude_id);   
		$article_id = (int) end($arr);
        $sql = "SELECT * FROM articles WHERE article_id = $article_id";
        $rs = mysql_query($sql);
        $row_details = mysql_fetch_assoc($rs);        
		$title = $row['title'];
		$metaD = $row['title'];
		$metaK = $row['title'];        
        break;

    case "tags":  
        $tieude_id = $tmp_uri[3];
        
        $arr = explode("-", $tieude_id);   
        $tag_id = (int) end($arr);
        $str_article_id = $model->getArticleIdByTagID($tag_id);
        break;  
   
        break;
    case "faq":                        
        //$title = $arrDetailPage["title"];
        //$metaD = $arrDetailPage["meta_d"];
        //$metaK = $arrDetailPage["meta_k"];
        break;   
    default :        
            $title = "The Palmy Hotel";
            $metaD = "The Palmy Hotel";
            $metaK = "The Palmy Hotel";        

        break;
}
?>